import {
    Vehicle
} from './vehicle.model'
const vehicle = new Vehicle()
Page({

    /**
     * 页面的初始数据
     */
    data: {
        vehicle: '',
        isAuth: false
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        let that = this
        that._loadData()
    },

    /**
     * 获取所有数据
     */
    _loadData() {
        let that = this
        // 是否授权
        wx.getSetting({
            success: (res) => {
                if (res.authSetting['scope.userInfo']) {
                    that.getLicenseData()
                    that.setData({
                        isAuth: true
                    })
                }
            }
        })
    },

    /**
     * 获取行驶证列表
     * @param {*} license_number 号牌号码
     */
    getLicenseData(license_number = '') {
        let that = this,
            param = {
                license_number: license_number
            }
        vehicle.getLicenseData(param).then((res) => {
            that.setData({
                vehicle: res.data
            })
        })
    },

    /**
     * 搜索车牌号
     * @param {*} options 搜索的值
     */
    onSearch(options) {
        this.getLicenseData(options.detail)
    },

    /**
     * 清空搜索
     */
    onClear() {
        this.getLicenseData()
    }
})